package com.gw.quotes.activity.fragment;

import java.util.List;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.annotation.view.ViewInject;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.gw.quotes.R;
import com.gw.quotes.activity.PriceInfoActivity;
import com.gw.quotes.adapter.Goods1Adapter;
import com.gw.quotes.entity.business.Priceinfo.AccessoryItem;
import com.yxw.view.NoScrollListView;

/**
 * 2014-10-22 下午7:26:33
 *
 *
 */
public class GoodsFragment1 extends Fragment {

	private View contextView = null;
	private Goods1Adapter goodsAdapter;
	/**
	 * 配件列表
	 */
	private List<AccessoryItem> accessoryList;
	
	@ViewInject(id = R.id.listview)
	private NoScrollListView listview;
	@ViewInject(id = R.id.no_result_layout)
	private RelativeLayout no_result_layout;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (contextView == null) {
			contextView = inflater.inflate(R.layout.fragment_activity_goods1,
					null);
		}
		ViewGroup parent = (ViewGroup) contextView.getParent();
		if (parent != null) {
			parent.removeView(contextView);
		}
		FinalActivity.initInjectedView(this, contextView);
		initView();
		return contextView;
	}

	private void initView() {
		accessoryList = ((PriceInfoActivity) getActivity()).getPriceinfo()
				.getAccessoryList();
		if (accessoryList == null || accessoryList.size() == 0) {
			listview.setVisibility(View.GONE);
			no_result_layout.setVisibility(View.VISIBLE);
		} else {
			goodsAdapter = new Goods1Adapter(getActivity(),
					R.layout.item_goods1, accessoryList);
			listview.setAdapter(goodsAdapter);
			listview.setVisibility(View.VISIBLE);
			no_result_layout.setVisibility(View.GONE);
		}
	}
}
